import { FormProps, FormSchema } from '/@/components/Table';
import { BasicColumn } from '/@/components/Table/src/types/table';
import { getJulyDictItemListByTypeApi } from '/@/api/admin/julyDictItemApi';
import { getClassificationTreeApi } from "/@/api/website/websiteClassificationApi";
import { uploadApi } from '/@/api/sys/upload';
import {h} from "vue";
import {Tag} from "ant-design-vue";
import {Tinymce} from "/@/components/Tinymce";



//表格显示列
export function getBasicColumns(): BasicColumn[] {
  // @ts-ignore
  return [
    {
      title: 'ID',
      dataIndex: 'recruitId',
      fixed: 'left',
      width: 100,
    },
    {
      title: '招聘岗位名称',
      dataIndex: 'recruitName',
      width: 150,

    },
    {
      title: '薪资',
      dataIndex: 'salary',
      width: 100,
    },
    {
      title: '上架状态',
      dataIndex: 'status',
      width: 150,
      customRender: ({record}) => {
        let status = record.status;
        let color = ''
        switch (status) {
          case '0':
            status = '上架';
            color = 'green'
            break;
          case '1':
            status = '下架';
            color = 'purple'
            break;
        }
        return h(Tag, {color: color}, () => status);
      },
      //sorter: true,
      //defaultHidden: true,
    }

  ];
}

export function getFormConfig(): Partial<FormProps> {
  return {
    labelWidth: 150,
    baseColProps: { lg: 6, md: 24 },
    schemas: formParamSchema,
  };
}


//编辑表单
export const formParamSchema: FormSchema[] = [
  {
    field: 'recruitName',
    label: '招聘岗位名称',
    component: 'Input',
  },
  {
    field: 'status',
    label: '上架状态',
    component: 'ApiSelect',
    componentProps: {
      api: getJulyDictItemListByTypeApi,
      params: { type: 'STATUS' },
      labelField: 'label',
      valueField: 'value',
    },
  },
];

//编辑表单
export const formSchema: FormSchema[] = [
  {
    field: 'recruitName',
    label: '招聘岗位名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'jobResponsibilities',
    label: '岗位职责',
    component: 'Input',

    required: true,
    render: ({model, field}) => {
      return h(Tinymce, {
        value: model[field],
        onChange: (value: string) => {
          model[field] = value;
        },
      });
    },
  },

  {
    field: 'qualifications',
    label: '任职条件',
    component: 'Input',
    required: true,
    render: ({model, field}) => {
      return h(Tinymce, {
        value: model[field],
        onChange: (value: string) => {
          model[field] = value;
        },
      });
    },
  },
  {
    field: 'salary',
    label: '薪资待遇',
    component: 'InputTextArea',
    required: true,
  },

  {
    field: 'deliveryMethods',
    label: '投递方式',
    component: 'Input',
    required: true,
  },
  {
    field: 'status',
    label: '上架状态',
    component: 'RadioButtonGroup',
    defaultValue: '0',
    required: true,
    componentProps: {
      options: [
        { label: '上架', value: '0' },
        { label: '下架', value: '1' },
      ],
    },
  },
];
